package com.sunxu.exercise4;

/**
 * ${DESCRIPTION}
 *
 * @author Sun
 * @create 2017-08-01-22:29
 */
public class MyThread2 extends Thread {
    @Override
    public void run() {
        try {
            for (int i = 0; i < 500000; i++) {
                if (this.isInterrupted()) {
                    System.out.println("已经是停止状态了，我要退出了!");
                    throw new InterruptedException();
                }
                System.out.println("i=" + (i + 1));
            }
            System.out.println("我被输出，如果此代码是for又继续运行，线程并未停止！");
        } catch (InterruptedException e) {
            System.out.println("进MyTread2.java类run方法中的catch");
            e.printStackTrace();
        }
    }
}
